package action;

import Impl.MessageDaoImpl;
import entity.Message;

import javax.servlet.ServletException;
import javax.servlet.annotation.ServletSecurity;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "ShowMessage")
public class ShowMessage extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("----------正在执行showMessage------------");
        Message message = new Message();
        MessageDaoImpl messageDao = new MessageDaoImpl();
        HttpSession session = request.getSession();
        int mid = Integer.parseInt(request.getParameter("id"));
        System.out.println("短信编号："+mid);
        String recipient = request.getParameter("uname");
        System.out.println("发件人或收件人"+recipient);
        message=messageDao.findMessageById(mid,recipient);
        session.setAttribute("message",message);
        request.getRequestDispatcher("/showMessage.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
